<template>
    <div class="wrapper">
        <v-head></v-head>
        <v-sidebar></v-sidebar>

        <div class="content-box" :class="{'content-collapse':collapse}">
            <v-tags></v-tags>
            <div class="content">
                <transition name="move" mode="out-in">
                    <keep-alive :include="tagsList">
                        <router-view></router-view>
                    </keep-alive>
                </transition>
                <el-backtop target=".content"></el-backtop>
            </div>
        </div>

        <!-- 修改密码dialog -->
        <v-modifyPwd :modify-pwd-dialog-visible='showModify'></v-modifyPwd>

        <!-- 新增/查看待办事项dialog -->
        <v-doItems :add-to-do-item-dialog-visible='showAddToDoItemDialog' :title='toDoItemTitle'></v-doItems>
    </div>
</template>

<script>
import vHead from './Header.vue';
import vSidebar from './Sidebar.vue';
import vTags from './Tags.vue';
import vModifyPwd from './ModifyPwd.vue';
import vDoItems from './DoItems.vue';
import bus from './bus';
import { Message } from 'element-ui';
export default {
    data() {
        return {
            tagsList: [],
            collapse: false,
            showModify: false,
            showAddToDoItemDialog: false,
            toDoItemTitle: '待办事项',

            showCustomConfirmDialog: false,
            tips: '',
        };
    },
    components: {
        vHead,
        vSidebar,
        vTags,
        vModifyPwd,
        vDoItems,
    },
    created() {
        // 使用bus进行各组件之间的通信

        bus.$on('collapse-content', msg => {
            this.collapse = msg;
        });

        // 只有在标签页列表里的页面才使用keep-alive，即关闭标签之后就不保存到内存中了。
        bus.$on('tags', msg => {
            let arr = [];
            for (let i = 0, len = msg.length; i < len; i++) {
                msg[i].name && arr.push(msg[i].name);
            }
            this.tagsList = arr;
        });

        // 接收组件事件
        bus.$on('showModifyPwd', msg => {
            this.showModify = msg;
        });

        // 接收组件事件
        bus.$on('showAddDoItem', args => {
            console.log(args);
            // 发送消息
            bus.$emit('resetToDoItemForm');
            this.showAddToDoItemDialog = args.show;
            this.toDoItemTitle = args.operate + "待办事项";
            // 编辑待办事项
            if (args.row) {
                // 向全局发送消息
                bus.$emit('fillEditToDoItemForm', args.row);
            }
        });
    },
};
</script>
